// pages/Transferbyfounder/Transferbyfounder.js
import {
    getTeamListexcludesup,
    setsupperadminapi
} from '../../api/app.js'
import user from '../../utils/user.js'
import {
    shake
} from '../../utils/util'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        key: '',
        isUp: false,
        id: '',
        name: '',
        teamList: [],
        userName: ''
    },
    changeipt(e) {
        console.log(e.detail.value);
        this.setData({
            teamList: [],
            key: e.detail.value
        })
        shake(() => {
            getTeamListexcludesup({
                companyId: user.companyId,
                userName: this.data.key
            }).then(res => {
                console.log(res, 'dsuygfshuy');
                res.forEach((ele, i) => {
                    ele.isselect = false
                })
                this.setData({
                    teamList: res
                })
            })
        }, 1000)

    },
    cancel() {
        wx.navigateBack()
    },
    cancelinner() {
        this.setData({
            isUp: false
        })
    },
    sureinner() {
        setsupperadminapi({
            userId: this.data.id
        }).then((res) => {
            user.reLogin().then(() => {
                app.toast('转让成功，正在为您跳转到首页！')
                setTimeout(() => {
                    wx.reLaunch({
                        url: '/pages/index/index'
                    })
                }, 1000)
            })
        })
    },
    sure() {
        if (this.data.name) {
            this.setData({
                isUp: true
            })
        } else {
            wx.showToast({
                title: '请选择',
                icon: 'error'
            })
        }

    },
    cancelinn() {
        this.setData({
            isUp: false
        })
    },
    changeselect(e) {
        this.data.id = e.currentTarget.dataset.id
        this.data.name = e.currentTarget.dataset.name
        this.data.teamList.forEach((ele, i) => {
            if (e.currentTarget.dataset.i === i) {
                ele.isselect = true
            } else {
                ele.isselect = false
            }
        })
        this.setData({
            name: this.data.name,
            teamList: this.data.teamList
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        user.waitLogin().then(() => {
            getTeamListexcludesup({
                companyId: user.companyId,
                userName: this.data.key
            }).then(res => {
                console.log(res, 'dsuygfshuy');
                res.forEach((ele, i) => {
                    ele.isselect = false
                })
                this.setData({
                    teamList: res
                })
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})